<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>内网穿透 | 小李的博客</title><meta name="author" content="蛇皮小李"><meta name="copyright" content="蛇皮小李"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="什么是内网穿透？内网穿透_百度百科 (baidu.com) NATNetwork Address Translation (NAT，网络地址转换),将内网地址转换为公网地址，其主要目的是为了解决IPv4地址短缺的问题。将一个或多个公网IP分给一个或多个内网设备使用，其基本类型有三种：  静态NAT（Static NAT）：将一个内部IP地址映射到一个固定的外部IP地址。一对一绑定   动态NAT（">
<meta property="og:type" content="article">
<meta property="og:title" content="内网穿透">
<meta property="og:url" content="https://lt-codehub.github.io.git/2023/12/23/%E4%B8%80%E6%96%87%E8%AE%B2%E9%80%8F%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/index.html">
<meta property="og:site_name" content="小李的博客">
<meta property="og:description" content="什么是内网穿透？内网穿透_百度百科 (baidu.com) NATNetwork Address Translation (NAT，网络地址转换),将内网地址转换为公网地址，其主要目的是为了解决IPv4地址短缺的问题。将一个或多个公网IP分给一个或多个内网设备使用，其基本类型有三种：  静态NAT（Static NAT）：将一个内部IP地址映射到一个固定的外部IP地址。一对一绑定   动态NAT（">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-12-23T12:26:26.000Z">
<meta property="article:modified_time" content="2023-12-28T15:59:34.600Z">
<meta property="article:author" content="蛇皮小李">
<meta property="article:tag" content="博客">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lt-codehub.github.io.git/2023/12/23/%E4%B8%80%E6%96%87%E8%AE%B2%E9%80%8F%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '内网穿透',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-12-28 23:59:34'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小李的博客"><span class="site-name">小李的博客</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">内网穿透</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-12-23T12:26:26.000Z" title="发表于 2023-12-23 20:26:26">2023-12-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-12-28T15:59:34.600Z" title="更新于 2023-12-28 23:59:34">2023-12-28</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="内网穿透"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="什么是内网穿透？"><a href="#什么是内网穿透？" class="headerlink" title="什么是内网穿透？"></a>什么是内网穿透？</h1><p><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/8597835?fr=aladdin">内网穿透_百度百科 (baidu.com)</a></p>
<h2 id="NAT"><a href="#NAT" class="headerlink" title="NAT"></a>NAT</h2><p>Network Address Translation (NAT，网络地址转换),将内网地址转换为公网地址，其主要目的是为了解决IPv4地址短缺的问题。将一个或多个公网IP分给一个或多个内网设备使用，其基本类型有三种：</p>
<ul>
<li><p><strong>静态NAT（Static NAT）：</strong>将一个内部IP地址映射到一个固定的外部IP地址。<strong>一对一绑定</strong></p>
<p><img src="https://s2.loli.net/2023/12/27/gNGzeW5FSs4cdhn.png" alt="未命名文件 (2)"></p>
</li>
<li><p><strong>动态NAT（Dynamic NAT）：</strong>内部设备通过动态分配的方式映射到一组外部IP地址。<strong>多对多动态匹配</strong></p>
<p><img src="https://s2.loli.net/2023/12/27/ATRIZmfWPS9d2rt.png" alt="未命名文件 (3)"></p>
</li>
<li><p><strong>端口地址转换 PAT（Port Address Translation）：</strong>PAT是动态NAT的一种形式，通过使用不同的端口号来映射多个内部设备到同一个公共IP地址，<strong>不同的内网设备使用同一公网IP的不同端口进行公网访问</strong>，大大缓解了IPv4的需求量</p>
<p><img src="https://s2.loli.net/2023/12/27/dUcG2AynE9IPspr.png" alt="未命名文件 (5)"></p>
</li>
</ul>
<h3 id="PAT"><a href="#PAT" class="headerlink" title="PAT"></a>PAT</h3><p>PAT既涉及到地址的装换，又涉及到端口的装换，PAT又分为连个方面：</p>
<ul>
<li><p>源NAT（Source NAT，SNAT）：修改数据包的源地址。源NAT改变第一个数据包的来源地址，它永远会在数据包发送到网络之前完成，数据包伪装就是一具SNAT的例子。</p>
</li>
<li><p>目的NAT（Destination NAT，DNAT）：修改数据包的目的地址。Destination NAT刚好与SNAT相反，它是改变第一个数据懈的目的地地址，如平衡负载、端口转发和透明代理就是属于DNAT。</p>
</li>
</ul>
<p><img src="https://s2.loli.net/2023/12/27/tdWjsCyIGDYSEp6.png" alt="未命名文件 (7)"></p>
<h3 id="工作流程详解"><a href="#工作流程详解" class="headerlink" title="工作流程详解"></a>工作流程详解</h3><p>NAT的基本工作原理是，当私有网主机和公共网主机通信的IP包经过NAT网关时，将IP包中的源IP或目的IP在私有IP和NAT的公共IP之间进行转换。</p>
<p>如图是192.168.1.2的内网主机和202.20.65.4的公网服务器的通信流程：</p>
<p><img src="https://s2.loli.net/2023/12/27/76oiFRSstWlGMZH.png" alt="image-20231227205353413"></p>
<p><strong>如果内网主机发出的请求包未经过NAT，那么当Web Server收到请求包，回复的响应包中的目的地址就是私网IP地址，在Internet上无法正确送达，导致连接失败。</strong></p>
<p>在上述过程中，**NAT Gateway在收到响应包后，就需要判断将数据包转发给谁。此时如果子网内仅有少量客户机，可以用静态NAT手工指定；但如果内网有多台客户机，并且各自访问不同网站，这时候就需要<code>连接跟踪（connection track）</code>**。如下图所示：</p>
<p><img src="https://s2.loli.net/2023/12/27/7t3LOFlVZrPNo9D.png" alt="image-20231227210140856"></p>
<p>在NAT Gateway收到客户机发来的请求包后，做<code>源地址转换</code>，并且将该连接记录保存下来，当NAT Gateway收到服务器来的响应包后，查找Track Table，确定转发目标，做目的地址转换，转发给客户机</p>
<p>以上述客户机访问服务器为例，当仅有一台客户机访问服务器时，NAT Gateway只须更改数据包的源IP或目的IP即可正常通讯。<strong>但是如果Client A和Client B同时访问Web Server，那么当NAT Gateway收到响应包的时候，就无法判断将数据包转发给哪台客户机</strong>，如下图所示</p>
<p><img src="https://s2.loli.net/2023/12/27/IbXpTwKMvQO2qRF.png" alt="image-20231227210441768"></p>
<p><strong>此时，NAT Gateway会在Connection Track中加入端口信息加以区分。如果两客户机访问同一服务器的源端口不同，那么在Track Table里加入端口信息即可区分，如果源端口正好相同，那么在时行SNAT和DNAT的同时对源端口也要做相应的转换，如下图所示</strong>。</p>
<p><img src="https://s2.loli.net/2023/12/27/kJANwWMUcsvipSI.png" alt="image-20231227210520777"></p>
<h2 id="内网穿透-NAT-Traversal"><a href="#内网穿透-NAT-Traversal" class="headerlink" title="内网穿透-NAT Traversal"></a>内网穿透-NAT Traversal</h2><p>内网穿透的出现的原因就是因为NAT的缺陷，只能由内网主机发起连接，外网主机不能主动访问内网主机.</p>
<p><img src="https://s2.loli.net/2023/12/27/ZzFQUMoV5p9Lte4.png" alt="未命名文件 (9)"></p>
<p><img src="https://s2.loli.net/2023/12/27/RtsDycvYMTGdA93.png" alt="未命名文件 (10)"></p>
<h2 id="STUN-打洞型"><a href="#STUN-打洞型" class="headerlink" title="STUN-打洞型"></a>STUN-打洞型</h2><p>Simple Traversal of UDP throught NAT-UDP穿越NAT的简单方法</p>
<p><img src="https://s2.loli.net/2023/12/27/PS3RicAZWJMT7sq.png" alt="未命名文件 (12)"></p>
<h2 id="TURN-转发型"><a href="#TURN-转发型" class="headerlink" title="TURN-转发型"></a>TURN-转发型</h2><p>Traversal Using Relay NAT-使用中继NAT进行穿越</p>
<p><img src="https://s2.loli.net/2023/12/27/6gVT2Fn1UDhYp3f.png" alt="未命名文件 (13)"></p>
<p>以下是STUN和TURN两种方式在对等通信中的优劣势对比，用表格呈现：</p>
<table>
<thead>
<tr>
<th>特性</th>
<th>STUN</th>
<th>TURN</th>
</tr>
</thead>
<tbody><tr>
<td>优势</td>
<td>- 无需中继服务器，直接建立对等连接</td>
<td>- 可以在存在NAT或防火墙的环境中建立连接</td>
</tr>
<tr>
<td></td>
<td>- 低延迟，直接设备间通信</td>
<td>- 解决了NAT和防火墙的限制</td>
</tr>
<tr>
<td></td>
<td>- 对于简单的NAT类型（如锥形NAT），通常可行</td>
<td>- 在所有情况下都可行，适用于复杂的网络环境</td>
</tr>
<tr>
<td></td>
<td>- 不涉及中继，不引入额外的带宽消耗</td>
<td></td>
</tr>
<tr>
<td>缺点</td>
<td>- 对于某些类型的NAT，可能无法提供足够的信息</td>
<td>- 引入了中继服务器，可能增加延迟和带宽消耗</td>
</tr>
<tr>
<td></td>
<td>- 在对称型NAT等复杂网络环境中有限制</td>
<td>- 中继服务器可能成为性能瓶颈</td>
</tr>
<tr>
<td></td>
<td>- 无法处理所有情况，需要配合其他技术（如ICE）</td>
<td>- 需要TURN服务器的支持</td>
</tr>
<tr>
<td></td>
<td></td>
<td>- 中继可能导致额外的费用</td>
</tr>
<tr>
<td>适用场景</td>
<td>- 实时通信应用，如音频、视频通话</td>
<td>- 当STUN无法直接建立连接时</td>
</tr>
<tr>
<td></td>
<td>- 对于简单的NAT环境</td>
<td>- 在复杂的NAT环境或存在防火墙的网络中</td>
</tr>
</tbody></table>
<p>需要根据具体的网络环境和应用需求来选择使用STUN、TURN还是它们的组合（如STUN + TURN + ICE）。在实际应用中，通常会先尝试使用STUN直连，只有在STUN无法成功建立连接时才转向使用TURN中继。</p>
<h1 id="内网穿透工具"><a href="#内网穿透工具" class="headerlink" title="内网穿透工具"></a>内网穿透工具</h1><h2 id="FRP"><a href="#FRP" class="headerlink" title="FRP"></a>FRP</h2><p><a target="_blank" rel="noopener" href="https://github.com/fatedier/frp/blob/master/README_zh.md">frp官方中文使用说明文档</a></p>
<p><a target="_blank" rel="noopener" href="https://mritd.me/2017/01/21/use-frp-for-internal-network-wear/">利用 frp 进行内网穿透</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.breakering.com/2018/09/28/frp/">内网穿透frp</a></p>
<p><a target="_blank" rel="noopener" href="https://ffis.me/experience/1266.html">使用frp搭建内网穿透和基友畅玩我的世界</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_43213815/article/details/121336968">使用frp配置内网(穿透[保姆级教程])</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/cenima/p/17849921.html">frp图解 附最新.toml配置文件</a></p>
<h2 id="natapp"><a href="#natapp" class="headerlink" title="natapp"></a>natapp</h2><p><a target="_blank" rel="noopener" href="https://natapp.cn/">NATAPP-内网穿透 基于ngrok的国内高速内网映射工具</a></p>
<p><a target="_blank" rel="noopener" href="https://juejin.im/post/5cad5e675188251b1b2f5517">内网穿透（mac，window，linux通用）1分钟实现外网访问电脑本地服务器</a></p>
<p><a target="_blank" rel="noopener" href="https://natapp.cn/article/natapp_newbie">NATAPP1分钟快速新手图文教程</a></p>
<h2 id="ngrok"><a href="#ngrok" class="headerlink" title="ngrok"></a>ngrok</h2><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/zhangguo5/article/details/77848658">超详细内网穿透(墙裂推荐,建议备份此文章)</a></p>
<p><a target="_blank" rel="noopener" href="https://luozm.github.io/ngrok">ngrok搭建指南</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/inconshreveable/ngrok">ngrok github地址及官方文档说明</a></p>
<p><a target="_blank" rel="noopener" href="https://ngrok.com/">ngrok官网</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/yjc_1111/article/details/79353718">10分钟教你搭建自己的ngrok服务器</a></p>
<p><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/33794707">ngrok 实现内网穿透</a></p>
<p><a target="_blank" rel="noopener" href="https://tsukkomi.org/post/use-ngrok-to-puch-the-nat">内网穿透之ngrok</a></p>
<p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/c273d3009ded">ngrok 内网映射</a></p>
<p><a target="_blank" rel="noopener" href="https://5xruby.tw/posts/easy-ngrok-by-nginx-ssh-tunnel/">ngrok 不求人：自己搭一個窮人版的 ngrok 服務</a></p>
<p><a target="_blank" rel="noopener" href="https://cjting.me/2016/05/21/ngrok-tutorial/">使用 Ngrok 实现内网穿透</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/dosgo/ngrok-c">ngrok c版本</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/hauntek/python-ngrokd">ngrok python版本</a></p>
<h2 id="ZeroTier"><a href="#ZeroTier" class="headerlink" title="ZeroTier"></a>ZeroTier</h2><p><a target="_blank" rel="noopener" href="https://blog.whsir.com/post-3685.html">无公网IP通过ZeroTier方便实现内网穿透（详细）</a></p>
<h2 id="Socket-Pipe"><a href="#Socket-Pipe" class="headerlink" title="Socket Pipe"></a>Socket Pipe</h2><p><a target="_blank" rel="noopener" href="https://joyqi.com/javascript/socket-pipe.html">纯手工自制的内网穿透瑞士军刀 Socket Pipe</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/joyqi/socket-pipe">Socket Pipe github</a></p>
<h2 id="Sunny-Ngrok"><a href="#Sunny-Ngrok" class="headerlink" title="Sunny-Ngrok"></a>Sunny-Ngrok</h2><p>Sunny-Ngrok同样是ngrok二次开发的内网穿透工具，支持http,https协议，同时支持更丰富的系统和语言：linux、win、mac、openwrt、 python、php等。</p>
<p><a target="_blank" rel="noopener" href="https://www.ngrok.cc/">Sunny-Ngrok官网</a><br><a target="_blank" rel="noopener" href="https://www.ngrok.cc/_book/">Sunny-Ngrok使用教程</a></p>
<h2 id="Lanproxy"><a href="#Lanproxy" class="headerlink" title="Lanproxy"></a>Lanproxy</h2><p>Lanproxy开源免费版，挺不错的，自己搭建还是不错的</p>
<ul>
<li>主页 <a target="_blank" rel="noopener" href="https://nat.nioee.com/">https://nat.nioee.com</a></li>
<li>lanproxy-go-client <a target="_blank" rel="noopener" href="https://github.com/ffay/lanproxy-go-client">https://github.com/ffay/lanproxy-go-client</a></li>
<li>发布包下载地址 <a target="_blank" rel="noopener" href="https://github.com/ffay/lanproxy/releases">https://github.com/ffay/lanproxy/releases</a></li>
<li>仓库地址：<a target="_blank" rel="noopener" href="https://github.com/ffay/lanproxy">https://github.com/ffay/lanproxy</a></li>
</ul>
<h2 id="autossh"><a href="#autossh" class="headerlink" title="autossh"></a>autossh</h2><p>ssh 配合autossh工具使用，因为autossh会容错，自动重新启动SSH会话和隧道。autossh是一个程序，用于启动ssh的副本并进行监控，在死亡或停止传输流量时根据需要重新启动它。 这个想法来自rstunnel（Reliable SSH Tunnel），但是在C中实现。作者的观点是，它不像匆匆忙忙的工作那么容易。使用端口转发环路或远程回显服务进行连接监视。在遇到连接拒绝等快速故障时，关闭连接尝试的速度。在OpenBSD，Linux，Solaris，Mac OS X，Cygwin和AIX上编译和测试; 应该在其他BSD上工作。免费软件。</p>
<p><a target="_blank" rel="noopener" href="https://www.harding.motd.ca/autossh/">autossh 官网</a><br><a target="_blank" rel="noopener" href="https://yangqiang.im/?p=698">SSH内网穿透</a></p>
<h1 id="搭建FRP"><a href="#搭建FRP" class="headerlink" title="搭建FRP"></a>搭建FRP</h1><p><a target="_blank" rel="noopener" href="https://gofrp.org/zh-cn/docs/examples/">官网示例</a>&amp;<a target="_blank" rel="noopener" href="https://github.com/gofrp/frp-doc/tree/master/content/zh-cn/docs">Github项目文档</a></p>
<h3 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h3><ul>
<li><p>公网服务器</p>
</li>
<li><p>内网主机</p>
</li>
<li><p>最新版本 frp(服务端&amp;客户端)</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://github.com/fatedier/frp/releases">下载</a></li>
</ul>
<p><img src="https://s2.loli.net/2023/12/27/qZBLNs9Qj7D5zdR.png" alt="image-20231227231819385"></p>
<p><strong>注：一定要注意看项目版本和指令集版本是不是对得上</strong></p>
</li>
</ul>
<h2 id="服务端搭建"><a href="#服务端搭建" class="headerlink" title="服务端搭建"></a>服务端搭建</h2><p>上传安装包或者使用wget下载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">下载 frp 并解压</span></span><br><span class="line">wget https://github.com/fatedier/frp/releases/download/v0.9.3/frp_0.9.3_linux_amd64.tar.gz</span><br><span class="line">tar -zxvf frp_0.9.3_linux_amd64.tar.gz</span><br><span class="line">cd frp_0.9.3_linux_amd64</span><br></pre></td></tr></table></figure>

<h3 id="通用配置"><a href="#通用配置" class="headerlink" title="通用配置"></a>通用配置</h3><p>编辑 <code>frps.ini/frps.toml</code> 如下</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[comm]</span></span><br><span class="line"><span class="comment">#客户端和服务端连接的端口，默认7000</span></span><br><span class="line"><span class="attr">bindPort</span> = <span class="number">7000</span> </span><br><span class="line"><span class="comment">#令牌，c/s端相同</span></span><br><span class="line"><span class="attr">token</span> = <span class="number">6</span>cIHJfhiYzsfl1Vef1lPFaq96qql9Mfi </span><br><span class="line"></span><br><span class="line"><span class="comment"># frp 控制面板，配置开启</span></span><br><span class="line"><span class="comment"># 可使用:服务器ip:7500 来访问面板</span></span><br><span class="line"><span class="attr">dashboard_port</span> = <span class="number">7500</span></span><br><span class="line"><span class="attr">dashboard_user</span> = admin</span><br><span class="line"><span class="attr">dashboard_pwd</span> = admin</span><br><span class="line"></span><br><span class="line"><span class="comment">#公网http服务访问端口，配置开启</span></span><br><span class="line"><span class="attr">vhost_http_port</span> = <span class="number">4000</span></span><br><span class="line"><span class="comment">#公网https服务访问端口，配置开启</span></span><br><span class="line"><span class="attr">vhost_https_port</span> = <span class="number">8090</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 默认日志输出位置(这里输出到标准输出)</span></span><br><span class="line"><span class="attr">log_file</span> = /dev/stdout</span><br><span class="line"><span class="comment"># 日志级别，支持: debug, info, warn, error</span></span><br><span class="line"><span class="attr">log_level</span> = info</span><br><span class="line"><span class="attr">log_max_days</span> = <span class="number">3</span></span><br></pre></td></tr></table></figure>

<p><strong>以上配置满足大多数情况其他具体配置说明请参考frp <a target="_blank" rel="noopener" href="https://github.com/fatedier/frp/blob/master/README_zh.md">README</a> 文档</strong></p>
<p>设置完成后执行 <code>./frps -c ./frps.toml</code> 或者<code>./frps -c ./frps.ini</code>启动即可</p>
<h3 id="使用-systemd搭建"><a href="#使用-systemd搭建" class="headerlink" title="使用 systemd搭建"></a>使用 systemd搭建</h3><p>在 Linux 系统下，使用 <code>systemd</code> 可以方便地控制 frps 服务端的启动、停止、配置后台运行以及开机自启动。</p>
<p>以下是具体的操作步骤：</p>
<ol>
<li><p><strong>安装 systemd</strong></p>
<p>如果您的 Linux 服务器上尚未安装 systemd，可以使用包管理器如 <code>yum</code>（适用于 CentOS&#x2F;RHEL）或 <code>apt</code>（适用于 Debian&#x2F;Ubuntu）来安装它：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 使用 yum 安装 systemd（CentOS/RHEL）</span></span><br><span class="line">yum install systemd</span><br><span class="line"></span><br><span class="line"><span class="comment"># 使用 apt 安装 systemd（Debian/Ubuntu）</span></span><br><span class="line">apt install systemd</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>创建 frps.service 文件</strong></p>
<p>使用文本编辑器 (如 vim) 在 <code>/etc/systemd/system</code> 目录下创建一个 <code>frps.service</code> 文件，用于配置 frps 服务。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo vim /etc/systemd/system/frps.service</span><br></pre></td></tr></table></figure>

<p>写入内容</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[Unit]</span></span><br><span class="line"><span class="comment"># 服务名称，可自定义</span></span><br><span class="line"><span class="attr">Description</span> = frp server</span><br><span class="line"><span class="attr">After</span> = network.target syslog.target</span><br><span class="line"><span class="attr">Wants</span> = network.target</span><br><span class="line"></span><br><span class="line"><span class="section">[Service]</span></span><br><span class="line"><span class="attr">Type</span> = simple</span><br><span class="line"><span class="comment"># 启动frps的命令，需修改为您的frps的安装路径</span></span><br><span class="line"><span class="attr">ExecStart</span> = /home/nat/frp/frps -c /home/nat/frp/frps.toml</span><br><span class="line"></span><br><span class="line"><span class="section">[Install]</span></span><br><span class="line"><span class="attr">WantedBy</span> = multi-user.target</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>使用 systemd 命令管理 frps 服务</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 启动frp</span></span><br><span class="line">sudo systemctl start frps</span><br><span class="line"><span class="comment"># 停止frp</span></span><br><span class="line">sudo systemctl stop frps</span><br><span class="line"><span class="comment"># 重启frp</span></span><br><span class="line">sudo systemctl restart frps</span><br><span class="line"><span class="comment"># 查看frp状态</span></span><br><span class="line">sudo systemctl status frps</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>设置 frps 开机自启动</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl <span class="built_in">enable</span> frps</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="客户端搭建"><a href="#客户端搭建" class="headerlink" title="客户端搭建"></a>客户端搭建</h2><p>客户端作为发起链接的主动方，只需要正确配置服务器地址，以及要映射客户端的哪些服务端口等即可</p>
<p>下载解压并编辑 <code>frpc.ini/frpc.toml</code> 文件</p>
<h3 id="通用配置-1"><a href="#通用配置-1" class="headerlink" title="通用配置"></a>通用配置</h3><figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通用配置</span></span><br><span class="line"><span class="section">[common]</span></span><br><span class="line"><span class="comment"># 服务端地址及端口</span></span><br><span class="line"><span class="attr">server_addr</span> = domain.com</span><br><span class="line"><span class="attr">server_port</span> = <span class="number">7000</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">log_file</span> = /dev/stdout</span><br><span class="line"><span class="attr">log_level</span> = info</span><br><span class="line"><span class="attr">log_max_days</span> = <span class="number">3</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#令牌，c/s端相同</span></span><br><span class="line"><span class="attr">token</span> = <span class="number">6</span>cIHJfhiYzsfl1Vef1lPFaq96qql9Mfi </span><br><span class="line"><span class="comment">#通过includes引入不同的代理配置</span></span><br><span class="line"><span class="attr">includes</span> = [<span class="string">&quot;./*.toml&quot;</span>]</span><br></pre></td></tr></table></figure>

<h3 id="SSH配置"><a href="#SSH配置" class="headerlink" title="SSH配置"></a>SSH配置</h3><p>新建文件<code>ssh.ini/ssh.toml</code></p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[ssh配置]</span></span><br><span class="line"><span class="attr">name</span> = ssh <span class="comment">#每一个代理的名称具有唯一性</span></span><br><span class="line"><span class="attr">type</span> = tcp</span><br><span class="line"><span class="comment">#公网访问的内网服务的地址和端口</span></span><br><span class="line"><span class="attr">local_ip</span> = <span class="number">127.0</span>.<span class="number">0.1</span></span><br><span class="line"><span class="attr">local_port</span> = <span class="number">22</span></span><br><span class="line"><span class="comment">#表示在 frp 服务端监听的端口，访问此端口的流量将被转发到本地服务的相应端口</span></span><br><span class="line"><span class="attr">remotePort</span> = <span class="number">6000</span> </span><br><span class="line"><span class="comment"># 是否开启加密(流量加密，应对防火墙)</span></span><br><span class="line"><span class="attr">use_encryption</span> = <span class="literal">true</span></span><br><span class="line"><span class="comment"># 是否开启压缩</span></span><br><span class="line"><span class="attr">use_gzip</span> = <span class="literal">true</span></span><br><span class="line"></span><br><span class="line">使用以下命令通过 SSH 访问内网机器，假设用户名为 test</span><br><span class="line"><span class="comment">#ssh -o Port=6000 test@x.x.x.x</span></span><br></pre></td></tr></table></figure>

<h3 id="Web服务配置"><a href="#Web服务配置" class="headerlink" title="Web服务配置"></a>Web服务配置</h3><p>新建文件<code>web.ini/web.toml</code></p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[web]</span></span><br><span class="line"><span class="attr">name</span> = web</span><br><span class="line"><span class="attr">type</span> = http</span><br><span class="line"><span class="attr">localPort</span> = <span class="number">80</span></span><br><span class="line"><span class="attr">customDomains</span> = www.yourdomain.com/公网服务器的IP地址</span><br><span class="line"></span><br><span class="line"><span class="section">[web]</span></span><br><span class="line"><span class="attr">name</span> = web2</span><br><span class="line"><span class="attr">type</span> = http</span><br><span class="line"><span class="attr">localPort</span> = <span class="number">8080</span></span><br><span class="line"><span class="attr">customDomains</span> = www.yourdomain2.com/公网服务器的IP地址</span><br></pre></td></tr></table></figure>

<p>最后使用 <code>./frpc -c frpc.ini</code> 启动即可</p>
<h4 id="Frp访问内网Web服务的流程"><a href="#Frp访问内网Web服务的流程" class="headerlink" title="Frp访问内网Web服务的流程"></a>Frp访问内网Web服务的流程</h4><p><strong>通过浏览器访问</strong></p>
<p>使用浏览器访问 <code>http://www.yourdomain.com:4000</code> 即可访问内网机器上的 80 端口服务，访问 <code>http://www.yourdomain2.com:4000</code> 可以访问内网机器上的 8080 端口服务。</p>
<h2 id="STCP配置-安全地暴露内网服务"><a href="#STCP配置-安全地暴露内网服务" class="headerlink" title="STCP配置-安全地暴露内网服务"></a>STCP配置-安全地暴露内网服务</h2><ol>
<li><p><strong>配置 frps.toml</strong></p>
<p>在 frps.toml 文件中添加以下内容：</p>
<figure class="highlight toml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">bindPort</span> = <span class="number">7000</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>部署 frpc 客户端并配置</strong></p>
<p>在需要将内网服务暴露到公网的机器上部署 frpc，并创建如下配置：</p>
<figure class="highlight toml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">serverAddr</span> = <span class="string">&quot;x.x.x.x&quot;</span></span><br><span class="line"><span class="attr">serverPort</span> = <span class="number">7000</span></span><br><span class="line"></span><br><span class="line"><span class="section">[[proxies]]</span></span><br><span class="line"><span class="attr">name</span> = <span class="string">&quot;secret_ssh&quot;</span></span><br><span class="line"><span class="attr">type</span> = <span class="string">&quot;stcp&quot;</span></span><br><span class="line"><span class="comment"># 只有与此处设置的 secretKey 一致的用户才能访问此服务</span></span><br><span class="line"><span class="attr">secretKey</span> = <span class="string">&quot;abcdefg&quot;</span></span><br><span class="line"><span class="attr">localIP</span> = <span class="string">&quot;127.0.0.1&quot;</span></span><br><span class="line"><span class="attr">localPort</span> = <span class="number">22</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>在访问者机器上部署并配置 frpc</strong></p>
<p>在想要访问内网服务的机器上也部署 frpc，并创建如下配置：</p>
<figure class="highlight toml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">serverAddr</span> = <span class="string">&quot;x.x.x.x&quot;</span></span><br><span class="line"><span class="attr">serverPort</span> = <span class="number">7000</span></span><br><span class="line"></span><br><span class="line"><span class="section">[[visitors]]</span></span><br><span class="line"><span class="attr">name</span> = <span class="string">&quot;secret_ssh_visitor&quot;</span></span><br><span class="line"><span class="attr">type</span> = <span class="string">&quot;stcp&quot;</span></span><br><span class="line"><span class="comment"># 要访问的 stcp 代理的名字</span></span><br><span class="line"><span class="attr">serverName</span> = <span class="string">&quot;secret_ssh&quot;</span></span><br><span class="line"><span class="attr">secretKey</span> = <span class="string">&quot;abcdefg&quot;</span></span><br><span class="line"><span class="comment"># 绑定本地端口以访问 SSH 服务</span></span><br><span class="line"><span class="attr">bindAddr</span> = <span class="string">&quot;127.0.0.1&quot;</span></span><br><span class="line"><span class="attr">bindPort</span> = <span class="number">6000</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>通过 SSH 访问内网机器</strong></p>
<p>使用以下命令通过 SSH 访问内网机器，假设用户名为 test：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -o Port=6000 <span class="built_in">test</span>@127.0.0.1</span><br></pre></td></tr></table></figure></li>
</ol>
<h1 id="搭建Lanproxy"><a href="#搭建Lanproxy" class="headerlink" title="搭建Lanproxy"></a>搭建Lanproxy</h1><p>可以不用tocmat环境，和java环境，因为该发布版本已经可以通过脚本启动了</p>
<h2 id="下载相关"><a href="#下载相关" class="headerlink" title="下载相关"></a>下载相关</h2><ul>
<li>下载地址：<a target="_blank" rel="noopener" href="https://file.nioee.com/d/2e81550ebdbd416c933f/">Private Seafile (nioee.com)</a></li>
<li>下载2个发布版本的即可</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/oRqpy6fjAOWJvgF.png"><img src="https://s2.loli.net/2021/12/30/oRqpy6fjAOWJvgF.png" alt="image-20211230181457121"></a></p>
<h2 id="宝塔环境"><a href="#宝塔环境" class="headerlink" title="宝塔环境"></a>宝塔环境</h2><ul>
<li>需要有java环境</li>
<li>可以通过直接安装java部署环境</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/bW8JLDFoli6jvy7.png"><img src="https://s2.loli.net/2021/12/30/bW8JLDFoli6jvy7.png" alt="image-20211230181728210"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/bW8JLDFoli6jvy7.png">image-20211230181728210</a></p>
<p>安装相关的tomcat环境即可，安装会默认放心端口，但是别忘了服务厂商的安全组也要放行哦</p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/4fT3GAyokERg5aB.png"><img src="https://s2.loli.net/2021/12/30/4fT3GAyokERg5aB.png" alt="image-20211230181816608"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/4fT3GAyokERg5aB.png">image-20211230181816608</a></p>
<p>查看下载的服务器目录：</p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/V9kYqh51LyUX4uH.png"><img src="https://s2.loli.net/2021/12/30/V9kYqh51LyUX4uH.png" alt="image-20211230182455499"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/V9kYqh51LyUX4uH.png">image-20211230182455499</a></p>
<p>配置代理服务器</p>
<p>server的配置文件放置在conf目录中，配置 config.properties</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server.bind</span>=<span class="string">0.0.0.0</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#与代理客户端通信端口</span></span><br><span class="line"><span class="attr">server.port</span>=<span class="string">4900</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#ssl相关配置</span></span><br><span class="line"><span class="attr">server.ssl.enable</span>=<span class="string">true</span></span><br><span class="line"><span class="attr">server.ssl.bind</span>=<span class="string">0.0.0.0</span></span><br><span class="line"><span class="attr">server.ssl.port</span>=<span class="string">4993</span></span><br><span class="line"><span class="attr">server.ssl.jksPath</span>=<span class="string">test.jks</span></span><br><span class="line"><span class="attr">server.ssl.keyStorePassword</span>=<span class="string">123456</span></span><br><span class="line"><span class="attr">server.ssl.keyManagerPassword</span>=<span class="string">123456</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#这个配置可以忽略</span></span><br><span class="line"><span class="attr">server.ssl.needsClientAuth</span>=<span class="string">false</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#WEB在线配置管理相关信息</span></span><br><span class="line"><span class="attr">config.server.bind</span>=<span class="string">0.0.0.0</span></span><br><span class="line"><span class="attr">config.server.port</span>=<span class="string">8090</span></span><br><span class="line"><span class="attr">config.admin.username</span>=<span class="string">admin</span></span><br><span class="line"><span class="attr">config.admin.password</span>=<span class="string">admin</span></span><br></pre></td></tr></table></figure>

<p>上传已经修改好的文件到云服务器中，如果配置了tomcat，就到tomcat的webapp下</p>
<p>如果没有配置环境，则就放一个自己能找到的位置，一般宝塔的网站都是在wwwroot下哦</p>
<p>进入到proxy-server-0.1目录下的bin，使用<code>./startup.sh</code>启动脚本即可</p>
<h2 id="域名解析"><a href="#域名解析" class="headerlink" title="域名解析"></a>域名解析</h2><p>在域名服务器厂商处将域名解析到服务即可。也可以使用的第三方的dns服务来隐藏服务器真实ip</p>
<h2 id="代理配置"><a href="#代理配置" class="headerlink" title="代理配置"></a>代理配置</h2><p>打开地址 <a target="_blank" rel="noopener" href="http://ip:8090/">http://ip:8090</a> ，使用上面配置中配置的用户名密码登录</p>
<p>如果配置了域名可以用任何解析到当前服务器的域名：8090端口也是可以的哦，默认是非https的哦</p>
<p>使用上面配置的管理员密码，默认账户是admin，密码admin登录管理面板</p>
<p>添加客户端，客户端名称自定义，秘钥随机生成。则是代表一个设备</p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/BP3xVsyOtH4KRTr.png"><img src="https://s2.loli.net/2021/12/30/BP3xVsyOtH4KRTr.png" alt="image-20211230182823310"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/BP3xVsyOtH4KRTr.png">image-20211230182823310</a></p>
<p>编辑配置</p>
<p>代理名称随意</p>
<p>公网端口：则是服务器中开放的端口（不能用已经使用了的端口）需要在宝塔和安全组中放行该端口</p>
<p>后端ip端口：则是该客户端需要开放的端口，如果相对于客户端来说是本地则用127.0.0.1，如果有固定的ip，则是相关的ip和端口。我这里是用的本地的hexo项目地址哦</p>
<blockquote>
<p>如果你是自己的家庭服务器，可能就有多个ip，或者你的客户端也是服务器，则也是相对固定的ip哦</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/ZVqr2yBKsYWRlf4.png"><img src="https://s2.loli.net/2021/12/30/ZVqr2yBKsYWRlf4.png" alt="image-20211230182918395"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/ZVqr2yBKsYWRlf4.png">image-20211230182918395</a></p>
<h2 id="win客户端配置"><a href="#win客户端配置" class="headerlink" title="win客户端配置"></a>win客户端配置</h2><p>客户端则是我的笔记本的电脑，则是要提供数据的一方</p>
<p>下载官方提供的相关客户端工具即可。目前我是win的环境，所以我下载的是win的环境下的客户端</p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/akiAU1VuyRQfOl4.png"><img src="https://s2.loli.net/2021/12/30/akiAU1VuyRQfOl4.png" alt="image-20211230183509853"></a></p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/akiAU1VuyRQfOl4.png">image-20211230183509853</a></p>
<p>配置启动脚本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">client_windows_amd64.exe -s 部署了代理的服务ip -p 4900 -k 24e17a3132c242578f1915bda0856496 -ssl true</span><br></pre></td></tr></table></figure>

<ul>
<li>client_windows_amd64.exe：客户端</li>
<li>部署了代理的服务ip：则是相关的ip</li>
<li>4900：部署的服务器配置中开放的ip</li>
<li>24e17a3132c242578f1915bda0856496：客户端验证的秘钥</li>
</ul>
<p>启动脚本在cmd中执行即可</p>
<p><a target="_blank" rel="noopener" href="https://s2.loli.net/2021/12/30/yrL7d8oA4gx2qBD.png"><img src="https://s2.loli.net/2021/12/30/yrL7d8oA4gx2qBD.png" alt="image-20211230183744455">
  </a></p>
<h1 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h1><p><a target="_blank" rel="noopener" href="https://fdlucifer.github.io/2019/11/29/Intranet-penetration/#%E5%B8%B8%E8%A7%81%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E6%96%B9%E6%B3%95%E5%8F%8A%E4%BB%B7%E6%A0%BC%E6%AF%94%E8%BE%83">超全内网穿透工具,github项目及方法</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://LT-codehub.github.io.git">蛇皮小李</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://lt-codehub.github.io.git/2023/12/23/%E4%B8%80%E6%96%87%E8%AE%B2%E9%80%8F%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">https://lt-codehub.github.io.git/2023/12/23/%E4%B8%80%E6%96%87%E8%AE%B2%E9%80%8F%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://LT-codehub.github.io.git" target="_blank">小李的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/12/23/%E5%9F%9F%E5%90%8D%E8%8E%B7%E5%8F%96/" title="域名获取"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">域名获取</div></div></a></div><div class="next-post pull-right"><a href="/2023/12/23/Hexo%E5%BB%BA%E7%AB%99/" title="Hexo建站"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Hexo建站</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">蛇皮小李</div><div class="author-info__description">记录自己的日常</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%EF%BC%9F"><span class="toc-number">1.</span> <span class="toc-text">什么是内网穿透？</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#NAT"><span class="toc-number">1.1.</span> <span class="toc-text">NAT</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#PAT"><span class="toc-number">1.1.1.</span> <span class="toc-text">PAT</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E8%AF%A6%E8%A7%A3"><span class="toc-number">1.1.2.</span> <span class="toc-text">工作流程详解</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F-NAT-Traversal"><span class="toc-number">1.2.</span> <span class="toc-text">内网穿透-NAT Traversal</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#STUN-%E6%89%93%E6%B4%9E%E5%9E%8B"><span class="toc-number">1.3.</span> <span class="toc-text">STUN-打洞型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#TURN-%E8%BD%AC%E5%8F%91%E5%9E%8B"><span class="toc-number">1.4.</span> <span class="toc-text">TURN-转发型</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E5%B7%A5%E5%85%B7"><span class="toc-number">2.</span> <span class="toc-text">内网穿透工具</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#FRP"><span class="toc-number">2.1.</span> <span class="toc-text">FRP</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#natapp"><span class="toc-number">2.2.</span> <span class="toc-text">natapp</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ngrok"><span class="toc-number">2.3.</span> <span class="toc-text">ngrok</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ZeroTier"><span class="toc-number">2.4.</span> <span class="toc-text">ZeroTier</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Socket-Pipe"><span class="toc-number">2.5.</span> <span class="toc-text">Socket Pipe</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Sunny-Ngrok"><span class="toc-number">2.6.</span> <span class="toc-text">Sunny-Ngrok</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Lanproxy"><span class="toc-number">2.7.</span> <span class="toc-text">Lanproxy</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#autossh"><span class="toc-number">2.8.</span> <span class="toc-text">autossh</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%90%AD%E5%BB%BAFRP"><span class="toc-number">3.</span> <span class="toc-text">搭建FRP</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87"><span class="toc-number">3.0.1.</span> <span class="toc-text">环境准备</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%90%AD%E5%BB%BA"><span class="toc-number">3.1.</span> <span class="toc-text">服务端搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%9A%E7%94%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">3.1.1.</span> <span class="toc-text">通用配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-systemd%E6%90%AD%E5%BB%BA"><span class="toc-number">3.1.2.</span> <span class="toc-text">使用 systemd搭建</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%90%AD%E5%BB%BA"><span class="toc-number">3.2.</span> <span class="toc-text">客户端搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%9A%E7%94%A8%E9%85%8D%E7%BD%AE-1"><span class="toc-number">3.2.1.</span> <span class="toc-text">通用配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SSH%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.2.</span> <span class="toc-text">SSH配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Web%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.3.</span> <span class="toc-text">Web服务配置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Frp%E8%AE%BF%E9%97%AE%E5%86%85%E7%BD%91Web%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%B5%81%E7%A8%8B"><span class="toc-number">3.2.3.1.</span> <span class="toc-text">Frp访问内网Web服务的流程</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#STCP%E9%85%8D%E7%BD%AE-%E5%AE%89%E5%85%A8%E5%9C%B0%E6%9A%B4%E9%9C%B2%E5%86%85%E7%BD%91%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.3.</span> <span class="toc-text">STCP配置-安全地暴露内网服务</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%90%AD%E5%BB%BALanproxy"><span class="toc-number">4.</span> <span class="toc-text">搭建Lanproxy</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E7%9B%B8%E5%85%B3"><span class="toc-number">4.1.</span> <span class="toc-text">下载相关</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9D%E5%A1%94%E7%8E%AF%E5%A2%83"><span class="toc-number">4.2.</span> <span class="toc-text">宝塔环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90"><span class="toc-number">4.3.</span> <span class="toc-text">域名解析</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE"><span class="toc-number">4.4.</span> <span class="toc-text">代理配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#win%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%85%8D%E7%BD%AE"><span class="toc-number">4.5.</span> <span class="toc-text">win客户端配置</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BC%95%E7%94%A8"><span class="toc-number">5.</span> <span class="toc-text">引用</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/23/%E5%9F%9F%E5%90%8D%E8%8E%B7%E5%8F%96/" title="域名获取">域名获取</a><time datetime="2023-12-23T12:27:08.000Z" title="发表于 2023-12-23 20:27:08">2023-12-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/23/%E4%B8%80%E6%96%87%E8%AE%B2%E9%80%8F%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" title="内网穿透">内网穿透</a><time datetime="2023-12-23T12:26:26.000Z" title="发表于 2023-12-23 20:26:26">2023-12-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/23/Hexo%E5%BB%BA%E7%AB%99/" title="Hexo建站">Hexo建站</a><time datetime="2023-12-23T12:26:08.000Z" title="发表于 2023-12-23 20:26:08">2023-12-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/20/Node.js%E5%AE%89%E8%A3%85/" title="Nodejs">Nodejs</a><time datetime="2023-12-20T03:37:29.000Z" title="发表于 2023-12-20 11:37:29">2023-12-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 蛇皮小李</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>